
<template>
  <div class="leaderManage">
    <CommonBtn label-name="管理层级设定" v-if="!button || (button.event!='add()' && button.event!='edit()') " :buttons="buttons" @onButtonClick="onButtonClick">
      <span slot="conditions" v-for="(item,index) of conditions" :key="index" v-if="item.checked">{{item.label+":"+item.value}}</span>
    </CommonBtn>
    <CommonList ref="list" v-if="!button || (button.event!='add()' && button.event!='edit()')" :buttons="buttons"
                :columns="columns" :listUrl="listUrl" @tableSelect="tableSelect" :conditions="conditions"></CommonList>
    <CommonEdit v-if="button && (button.event=='add()' || button.event=='edit()')"
                :outBtn="button" :props="add"
                :original-data="row" :add-url="$api.API_INSERTMANAGEMENTHIERARCHY" :edit-url="$api.API_UPDATEMANAGEMENTHIERARCHY"
                @editBack="editBack"></CommonEdit>
    <search-pop-up :out-btn="button"
                   :props="columns" @close="close"
                   :out-conditions="conditions"
                   @conditionChange="conditionChange"></search-pop-up>
    <CommonExport :out-btn="button" :props="columns"
                  @close="close" :export-url="$api.API_MANAGEMENTHIERARCHY_EXPORT" :conditions="conditions"></CommonExport>

    <EnsurePopUp :out-btn="button" @close="close" @refresh="conditionChange" :original-data="row"
                 :delete-url="$api.API_SET_MANAGEMENT_HIERARCHY"></EnsurePopUp>
  </div>
</template>

<script>
    import CommonList from "../../common/CommonList"
    import CommonBtn from "../../common/CommonBtn";
    import CommonEdit from "../../common/CommonEdit";
    import SearchPopUp from "../../common/SearchPopUp";
    import CommonExport from "../../common/CommonExport";
    import EnsurePopUp from "../../common/EnsurePopUp";
    export default {
        name:'leaderManage',
        data(){
            return{
                buttons:[
                    this.$config.BTNS.ADD,
                    this.$config.BTNS.EDIT,
                    this.$config.BTNS.DELETE,
                    this.$config.BTNS.FORBIDEN,
                    this.$config.BTNS.ENABLE,
                    this.$config.BTNS.EXPORT,
                    this.$config.BTNS.SEARCH
                ],
                columns:[
                    {
                        prop:'positionCode',
                        label:'职位代码',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'positionName',
                        label:'管理层级',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'isValid',
                        label:'是否有效'
                    },
                    {
                        prop:'createUserName',
                        label:'创建者'
                    },
                    {
                        prop:'modifyUserName',
                        label:'最后修改者'
                    },
                    {
                        prop:'createTime',
                        label:'创建时间'
                    },
                    {
                        prop:'modifyTime',
                        label:'最后修改时间'
                    }
                ],
                listUrl:this.$api.API_MANAGEMENTHIERARCHY_LIST,
                button:null,
                add:{
                    label:'管理层级',
                    addItems:[
                        {name:'职位代码',prop:'positionCode',required:true,type:'text',disable:true,placeholder:'系统自动生成'},
                        {name:'职位名称',prop:'positionName',type:'text',required:true},
                        {name:'备注',prop:'memo',type:'textarea'}
                    ],
                },
                conditions:[],
                row:{}
            }
        },
        methods:{
            onButtonClick(item) {
                if (item.event == 'edit()' || item.event == 'Delete()' || item.event == 'disable()' || item.event == 'enable()') {
                    if (!this.row || JSON.stringify(this.row) == '{}') {
                        this.$message.error("请选择一行数据")
                        return
                    }
                }
                if (item.event == 'add()') {
                    this.row = {}
                }

                this.button = item
            },
            editBack(item) {
                this.button = item
            },
            tableSelect(row) {
                this.row = row
                //this.$delete (this.row,'createTime')
                //this.$delete (this.row,'modifyTime')
            },
            conditionChange(conditions) {
                this.$refs.list.search()
            },
            close(item) {
                this.button = item
            }
        },
        components:{CommonExport, SearchPopUp, CommonList,CommonBtn,CommonEdit,EnsurePopUp},
    }
</script>
